package rs.pnv.merchant.handler;

import javax.xml.transform.Source;
import javax.xml.ws.handler.LogicalHandler;
import javax.xml.ws.handler.LogicalMessageContext;
import javax.xml.ws.handler.MessageContext;

import rs.pnv.util.DocumentUtil;

public class CryptoHandler implements LogicalHandler<LogicalMessageContext> {

	@Override
	public boolean handleMessage(LogicalMessageContext context) {

		System.out.println("CryptoHandler.handleMessage()");

		Boolean isResponse = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

		Source source = context.getMessage().getPayload();
		try {
			DocumentUtil.printSource(source);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		if (isResponse) {
			System.out.println("kriptovanje...");

			return true;
		} else {
			System.out.println("dekriptovanje...");

			return true;
		}

	}

	@Override
	public boolean handleFault(LogicalMessageContext context) {

		// ako vraća false, znači da NE treba da se pozove handleFault metoda od sledećeg handler-a.
		// dakle, vratiti true, ako POSTOJI greška.
		return true;
	}

	@Override
	public void close(MessageContext context) {
		// TODO Auto-generated method stub

	}

}
